<?php

namespace App\Controller\Backend;

use App\Entity\AdminUserGroup;
use App\Message\Order;
use App\Message\SmsLog;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class DefaultController extends AbstractController
{
    /**
     * User: Gao
     * Date: 2020/3/21
     * Description: 管理模块
     * @param $sonata_admin
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function AdminModule($sonata_admin)
    {
        $admin_user = $this->getUser();
        if (!is_object($admin_user)) {
            throw new AccessDeniedException('未登录，无权限访问');
        }

        $admin_modules = [];
        $admin_user_group = $this->getDoctrine()->getRepository(AdminUserGroup::class)->find($admin_user->getAdminUserGroupId());
        if (is_object($admin_user_group)) {
            // 获取可访问的模块
            $admin_modules = $this->getDoctrine()->getRepository(AdminUserGroup::class)->getAdminModuleByAdminUserGroup($admin_user_group);
        }

        return $this->render('backend/default/admin_module.html.twig', [
            'admin_modules' => $admin_modules,
            'sonata_admin' => explode('|', $sonata_admin)
        ]);
    }

    /**
     * User: gao
     * Date: 2020/3/20
     * Description: 用户信息区块
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function AdminUserInfo()
    {
        return $this->render('backend/default/admin_user_info.html.twig', []);
    }

    /**
     * User: Gao
     * Date: 2020/3/28
     * Description: 控制面板
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function DashboardModule()
    {
        $admin_user = $this->getUser();
        if (!is_object($admin_user)) {
            throw new AccessDeniedException('未登录，无权限访问');
        }

        $admin_modules = [];
        $admin_user_group = $this->getDoctrine()->getRepository(AdminUserGroup::class)->find($admin_user->getAdminUserGroupId());
        if (is_object($admin_user_group)) {
            // 获取可访问的模块
            $admin_modules = $this->getDoctrine()->getRepository(AdminUserGroup::class)->getAdminModuleByAdminUserGroup($admin_user_group);
        }

        return $this->render('backend/default/dashboard_module.html.twig', [
            'admin_modules' => $admin_modules,
        ]);
    }
}
